package rpc.core.registry;

import java.util.Objects;

public class RegistryItem {

  private String id;
  private String addr;
  private int port;
  private String group;

  public String getDirect() {
    return this.addr + ":" + port;
  }

  public String getAddr() {
    return addr;
  }

  public RegistryItem setAddr(String addr) {
    this.addr = addr;
    return this;
  }

  public int getPort() {
    return port;
  }

  public RegistryItem setPort(int port) {
    this.port = port;
    return this;
  }

  public String getGroup() {
    return group;
  }

  public RegistryItem setGroup(String group) {
    this.group = group;
    return this;
  }

  public String getId() {
    return id;
  }

  public RegistryItem setId(String id) {
    this.id = id;
    return this;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (!(o instanceof RegistryItem)) {
      return false;
    }
    RegistryItem that = (RegistryItem) o;
    return getPort() == that.getPort() &&
        Objects.equals(getAddr(), that.getAddr()) &&
        Objects.equals(getGroup(), that.getGroup());
  }

  @Override
  public int hashCode() {
    return Objects.hash(getAddr(), getPort(), getGroup());
  }
}
